<div id="out-let-check-in-view">
  <div class="pageheader">
    <h2><i class="fa fa-home"></i>到期续租{{contractData?('(合同号：'+contractData.uuid+')'):''}}</h2>
    <div class="al-header-right">
      <button type="button" class="btn btn-warning" ng-click="$root.goBack('house-detail')">返回</button>
    </div>
  </div>
  <div class="page">
    <ng-form name="contractForm" class="form-horizontal">
      <div class="form-group">
        <h4 class="text-center">房间信息</h4>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">续租方式</label>
        <div class="col-sm-3">
          <nobr>
            <label class="ui-radio" ng-repeat="option in reletTypeList">
              <input name="status" ng-value="option.value"
                     ng-readonly="contractNew.created"
                     ng-change="changeReLetWay()"
                     type="radio" ng-model="contractNew.reletType">
              <span>{{option.name}}</span>
            </label>
          </nobr>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">公寓</label>
        <div class="col-sm-3" ng-if="apartmentList.length>0">
          <select ng-model="contractNew.apartmentId" class="form-control" ng-if="$root.storeAu==undefined"
                  ng-change="loadBuilding()"
                  ng-disabled="contractNew.created || contractNew.reletType==1"
                  ng-options="option.id as option.name for option in apartmentList"></select>
          <div class="form-control info-text"
               ng-if="$root.storeAu!=undefined">{{contractNew.apartmentId|constantTransfer:apartmentList:'id'}}</div>
        </div>
        <label class="control-label col-sm-2">楼栋</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.buildingId" ng-readonly="contractNew.created || contractNew.reletType==1"
                  class="form-control" ng-change="loadFloor()"
                  ng-disabled="contractNew.created || contractNew.reletType==1"
                  ng-options="option.id as option.name for option in buildingList"></select>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">楼层</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.floor"
                  ng-readonly="contractNew.created || contractNew.reletType==1 || contractNew.buildingId==undefined"
                  ng-disabled="contractNew.created || contractNew.reletType==1 || contractNew.buildingId==undefined"
                  class="form-control" ng-change="loadHouse()"
                  ng-options="option.id as option.name for option in floorList"></select>
        </div>
        <label class="control-label col-sm-2">房间号</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.houseId"
                  ng-readonly="contractNew.created || contractNew.reletType==1 || contractNew.floor==undefined"
                  ng-disabled="contractNew.created || contractNew.reletType==1 || contractNew.floor==undefined"
                  class="form-control" ng-change="pickHouse()"
                  ng-options="option.id as option.houseNo for option in houseList"></select>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">租房方式</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.payWay"
                  ng-readonly="contractNew.created || houseInfo==undefined"
                  ng-disabled="contractNew.created || houseInfo==undefined"
                  ng-change="getHousePrice()"
                  class="form-control"
                  ng-options="option.value as option.name for option in payWayList"></select>
        </div>
        <label class="control-label col-sm-2">租期</label>
        <div class="col-sm-3">
          <select ng-model="contractNew.lease"
                  ng-readonly="contractNew.created || houseInfo==undefined"
                  ng-disabled="contractNew.created || houseInfo==undefined"
                  ng-change="getHousePrice()"
                  class="form-control"
                  ng-options="option.value as option.name for option in leaseList"></select>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">合同开始日期<span class="attr-need">*</span></label>
        <div class="col-sm-3">
          <div class="input-group">
            <input class="form-control" type="text" uib-datepicker-popup="yyyy-MM-dd" readonly
                   ng-model="contractNew.leaseStart" is-open="enterStart"
                   close-text="关闭" current-text="今天" clear-text="清空" required
                   ng-change="getHousePrice()"
                   placeholder=""/>
            <span class="input-group-btn">
                <button type="button" class="btn btn-default" ng-click="enterStart=true" disabled>
                  <i class="glyphicon glyphicon-calendar"></i>
                </button>
              </span>
          </div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">月租金</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{housePrice==undefined?'--':housePrice.rental}}</div>
        </div>
        <label class="control-label col-sm-2">押金</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{housePrice==undefined?'--':housePrice.deposit}}</div>
        </div>
      </div>
      <div class="form-group" ng-if="housePrice && housePrice.activityList && housePrice.activityList.length>0">
        <label class="control-label col-sm-2 col-sm-offset-1">优惠活动</label>
        <div class="col-sm-9">
          <select ng-model="contractNew.activityId" class="form-control"
                  ng-readonly="contractNew.created"
                  ng-options="option.id as option.ruleName for option in housePrice.activityList"></select>
        </div>
      </div>
    </ng-form>
    <ng-form class="form-horizontal">
      <div class="form-group">
        <h4 class="text-center">原合同信息</h4>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">合同号</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.uuid}}</div>
        </div>
        <label class="control-label col-sm-2">公寓</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.apartmentName}}</div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">楼栋</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.buildingName}}</div>
        </div>
        <label class="control-label col-sm-2">房间号</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.houseNo}}</div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">租金</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.rental}}</div>
        </div>
        <label class="control-label col-sm-2">租金</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.deposit}}</div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">租期</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.leaseName}}</div>
        </div>
        <label class="control-label col-sm-2">付款方式</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.payWayName}}</div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">合同开始日期</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.leaseStart|dateTransfer:'YYYY-MM-DD'}}</div>
        </div>
        <label class="control-label col-sm-2">合同结束日期</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.leaseEnd|dateTransfer:'YYYY-MM-DD'}}</div>
        </div>
      </div>
      <div class="form-group">
        <h4 class="text-center">退款信息</h4>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">押金总额</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.deposit}}</div>
        </div>
        <label class="control-label col-sm-2">扣款总额</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{contractNew.sumConsumption}}</div>
        </div>
      </div>
      <div class="form-group">
        <label class="control-label col-sm-2 col-sm-offset-1">实退押金</label>
        <div class="col-sm-3">
          <div class="form-control info-text">{{oriContract.deposit-contractNew.sumConsumption}}</div>
        </div>
      </div>
      <div class="form-group" ng-repeat="item in consumptions">
        <label class="control-label col-sm-2 col-sm-offset-1">扣款费用{{$index+1}}</label>
        <div class="col-sm-2">
          <div class="input-group">
            <span class="input-group-addon">￥</span>
            <input type="number" class="form-control" readonly
                   ng-model="item.money">
          </div>
        </div>
        <div class="col-sm-5">
          <input type="text" class="form-control" readonly ng-model="item.description" placeholder="备注">
        </div>
        <div class="col-sm-2" ng-if="!contractData">
          <button class="btn btn-warning"
                  ng-click="removeConsumption(item)">移除
          </button>
        </div>
      </div>
      <div class="form-group" ng-if="!contractData">
        <h4 class="text-center">增加扣款</h4>
      </div>
      <div class="form-group" ng-if="!contractData">
        <label class="control-label col-sm-2 col-sm-offset-1">扣款费用</label>
        <div class="col-sm-2">
          <div class="input-group">
            <span class="input-group-addon">￥</span>
            <input type="number" class="form-control" ng-model="newConsumption.money" required>
          </div>
        </div>
        <div class="col-sm-5">
          <input type="text" class="form-control" ng-model="newConsumption.description" placeholder="备注">
        </div>
        <div class="col-sm-2">
          <button class="btn btn-primary"
                  ng-disabled="offLeaseOver || !newConsumption.money || !newConsumption.description"
                  ng-click="addConsumption()">添加
          </button>
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-4"></div>
        <div class="col-sm-4" style="text-align:center;">
          <button class="btn btn-primary" ng-if="!contractNew.created"
                  ng-disabled="contractNew.creating || contractForm.$invalid || personForm.$invalid"
                  ng-click="confirmReLet()">确认续租
          </button>
          <button class="btn btn-warning" ng-if="contractNew.created"
                  ng-click="printContract()">合同打印
          </button>
        </div>
        <div class="col-sm-4"></div>
      </div>
    </ng-form>
    <contract-payment-form ng-if="contractData && billId"
                           bill-id="billId" contract-data="contractData"></contract-payment-form>
    <ng-form class="form-horizontal form-validation">
      <div class="form-group" ng-if="contractData.status==4 || contractData.status==8">
        <h4 class="text-center">入住信息</h4>
      </div>
      <div class="form-group" ng-if="contractData.status==4 || contractData.status==8">
        <label class="control-label col-sm-2 col-sm-offset-1">业务员<span class="attr-need">*</span></label>
        <div class="col-sm-3">
          <input class="form-control" type="text" required ng-readonly="contractData.status==8"
                 ng-model="checkIn.receptionist">
        </div>
        <label class="control-label col-sm-2">渠道</label>
        <div class="col-sm-3">
          <select ng-model="checkIn.buzType" class="form-control"
                  ng-readonly="contractData.status==8"
                  ng-disabled="contractData.status==8"
                  ng-options="option.value as option.name for option in channelTypeList"></select>
        </div>
      </div>
      <div class="form-group" ng-if="contractData.status==4 || contractData.status==8">
        <label class="control-label col-sm-2 col-sm-offset-1">备注</label>
        <div class="col-sm-8">
          <textarea class="form-control" ng-readonly="contractData.status==8"
                    placeholder="填写备注信息"
                    ng-model="checkIn.contractPicture"></textarea>
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-4"></div>
        <div class="col-sm-4 text-center">
          <button class="btn btn-success" ng-if="contractData.status==4"
                  ng-disabled="!checkIn.receptionist"
                  ng-click="reletCheckIn()">续租入住
          </button>
        </div>
        <div class="col-sm-4"></div>
      </div>
    </ng-form>
  </div>
</div>